﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyPublisher.Data
{
    public partial class Publication
    {
        public Publication()
        {
        }

        public void AddSubmit()
        {
            using (pubdbEntities context = new pubdbEntities())
            {
                context.AddToPublication(this);
                context.SaveChanges();
            }
        }

        public IEnumerable<Publication> GetAll()
        {
            using (pubdbEntities context = new pubdbEntities())
            {
                return context.Publication.Select(c =>c).ToArray();
            }
        }

        public IEnumerable<Publication> GetById(Guid id)
        {
            using (pubdbEntities context = new pubdbEntities())
            {
                return context.Publication.Where(c=>c.PublicationId==id).Select(c => c).ToArray();
            }
        }

        public IEnumerable<Publication> GetByUerName(string userName)
        {
            using (pubdbEntities context = new pubdbEntities())
            {
                return context.Publication.Where(c => c.UserName.Contains(userName)).Select(c => c).ToArray();
            }
        }

        public IEnumerable<Publication> GetByProvider(string provider)
        {
            using (pubdbEntities context = new pubdbEntities())
            {
                return context.Publication.Where(c => c.Provider.Contains(provider)).Select(c => c).ToArray();
            }
        }
    }
}
